import { Action } from "@/mdesign-lib/mdesign-app.umd.js";
import { ActionKey } from "@/mdesign-lib/mdesign-app.umd.js";
import { shell } from "electron";

export class OpenCoworkAction extends Action {
  keyName = "openCowork" as ActionKey;
  desc = "openCowork";

  async run() {
    const token = app.global.token;
    const user = app.global.user;
    let baseURL = app.global.coworkAddress;

    if (user && token && baseURL) {
      if (!baseURL.startsWith("http://")) {
        baseURL = "http://" + baseURL;
      }
      const url = `${baseURL}/#/login?token=${token}`;
      console.log("url", url);
      shell.openExternal(url);
    }
  }

  onSysMenuClick() {
    this.run();
  }
}
